Copyright: Magma Systems


yesyesyesyesnono&PrintyesTRUEMagma Editormagmaedyes17/02/95


Table of Contents

Introduction

Initializing the Editor Class

Creating an Editor Window

Edit Styles

The Editor and Memory

Giving the Parent a Shot at Messages

The MAGMAED.INI File

Notifications When Reading a File

Owner Drawn Lines

Message Reference

Cursor Movement Messages

Bookmark Messages

Character Insertion & Deletion Messages

File Input/Output Messages

Search and Replace Messages

Selecting, Cutting, Copying and Pasting Text

Formatting Messages

Undo Messages

Configuration Messages

Owner Drawn Messages

Status Messages

Keyboard Macro Messages

Windows API Messages

Help Messages

Notification Codes


Introduction

Magma Editor DLL for Microsoft Windows

(C) Copyright 1994-1995 Magma Systems  All Rights Reserved

Magma Systems

15 Bodwell Terrace

Millburn, New Jersey  07041

USA

(201) 912-0192  (voice)

(201) 912-0103  (fax)

(201) 912-0668  (BBS, 9600-1200 N-8-1)

Compuserve :	75300,2062

To get to our conference, GO MAGMA

Bix        :	'magma'

To get to our conference, 'join magma'

Internet   :	75300.2062@compuserve.com

magma@bix.com

Introduction

The Magma Editor DLL is an edit control for Win16 and Win32 which provides a powerful alternative to the standard Microsoft Windows edit control. The Magma Editor (ME for short) is a line oriented text editing kernel which can be controlled by an application through a series of messages or through a high-level C-like macro language. You can think of the ME DLL as being a "BRIEF in a box".

The editor kernel provides the following features and enhancements over the standard Windows editoc control :

- The size of the text is limited by the amount of memory Windows can globally allocate. On the other hand, the standard Windows edit control is limited to 64K of text.

- Regular expression search and substitution

- Various block operations. Line marking, column marking, block marking, and discontiguous line marking.

- Keyboard macros

- Messages to read and write to files.

- More varieties of cursor movement. Ability to jump to a specific line, and to set bookmarks in the text.

- The ability to be in overstrike as well as in insert mode.


Initializing the Editor Class

To access the Magma Edit Control dynamic link library from within your Windows application, you must make the following call :

if (LoadLibrary("MAGMAED.DLL") < (HMODULE) 32)

return FALSE;

The LoadLibrary() function attempts to load the editor DLL, and if it succeeds, returns a module handle which is greater than or equal to 32. If a value less than 32 is returned, then the editor DLL could not be loaded.

You must make sure that the DLL is either present in your current working directory, or in a directory which is in your DOS path.

The startup routine inside of MAGMAED.DLL registers a global class called "MagmaEdit". This is the class name of an editor control.


Creating an Editor Window

Creating an editor window is just like creating any other control window. You can use a call to the CreateWindow function or, if you use the editor window as part of a dialog box, you can specify the control in your RC file.

A typical use of the CreateWindow function is as follows:

HWND hEdit;

hEdit = CreateWindow("MagmaEdit",

                     NULL,

                     WS_CHILD | WS_VISIBLE | WS_MAXIMIZE,

                     0, 0, 200, 100,

                     hWnd,

                     idCtrl,

                     GetWindowWord(hWnd, GWW_HINSTANCE),

                     (LPSTR) lpFileName);

The classname is MagmaEdit, and it has no initial text. The window style dictates that it is a visible child window, with hWnd as the parent window. You may give the editor window a unique control identifier in order to distinguish it from other controls or editor windows. The initial position within the parent's client area is 0, 0,  and the edit control is 200 pixels wide and 100 pixels high. The final argument may be the name of the file which will be associated with this editor window. If the file already exists, then the contents of the file will be read into the editor window.

NOTE FOR MFC USERS

In Windows, the last argument to the CreateWindow or CreateWindowEx functions is a 4-byte piece of data which will be passed as part of  the WM_CREATE message. This piece of data will appear in the 'lpParams' member of the CREATESTRUCT which is passed as the lParam value to the WM_CREATE message.

By default, if the value in CreateStruct.lpParam is not NULL, the Magma Editor DLL will consider it to be a far pointer to the name of a file to read into the editor buffer. However, some frameworks like MFC like to use the lpParam value for their own purposes. They do not pass a file name in the lpParam argument to CreateWindow.

In order to tell the Magma Editor DLL to ignore the lpParam value of the CREATESTRUCT, you can set a certain variable in the MAGMAED.INI file. If the value of the IgnoreCreateParams variable is set to a non-zero, then the CreateStruct's lpParam value will be ignored. Instead, the editor will create an empty file called Untitled.

In MAGMAED.INI:

[options]

IgnoreCreateParams=1


Edit Styles

The Magma Editor DLL supports some of the style bits which are associated with the normal Windows multiline edit control.

In additon to the standard style, the editor supports the following style bits.

ES_WANTTAB

This is used when an edit control is part of a dialog box. The editor examines this style when it processes the WM_GETDLGCODE message in order to let the Windows dialog manager know whether it want to keep the tabs.

ES_OWNERDRAW

Used to allow the application to render a line of the edit control.  See the ES_HASSTRINGS style.

ES_HASSTRINGS

Tells the edit control that there is a string of text associated with every owner-drawn line in the buffer.


The Editor and Memory

The Magma Edit control has no size limitations. It can use as much memory as Windows will globally allocate. This includes the virtual memory pool which you may have set up as part of the 386 version of Windows. The standard Windows edit control can only use at most 64K of data because it uses LocalAlloc for the edit buffer.


Giving the Parent a Shot at Messages

The editor control has default behavior for the various mouse actions. However, some applications might want to override the default behavior of the edit control. Before the editor control processes the following messages :

WM_MBUTTONDOWN

WM_RBUTTONDOWN

WM_LBUTTONDBLCLK

WM_MBUTTONDBLCLK

WM_RBUTTONDBLCLK

it first sends these messages up to the parent. If the parent processes these messages, it should return a non-zero value to the editor control. If it returns 0 to the editor, then the editor will take its default action for these messages.

Example :

   In the parent's window procedure :

  case WM_RBUTTONDOWN :

    PopupMyMenu(); /* Put up a popup menu */

    return TRUE;   /* Yes, I processed it */

  case WM_MBUTTONDOWN   :

  case WM_LBUTTONDBLCLK :

  case WM_MBUTTONDBLCLK :

  case WM_RBUTTONDBLCLK :

    return FALSE;


The MAGMAED.INI File

When an editor control is created, the editor searches for an initialization file called MAGMAED.INI. If this file is found, then the editor scans it for various values which the editor uses.

The options section contains the values of  various general purpose editor options. Most of the options can be set by using the ME_SETOPTION message. Most of these options are discussed in the Options section of this manual.

[options]

AutoIndent=(0 or 1)

AutoReformat=(0 or 1)

EntabLine=(0 or 1)

GoFreeSpace=(0 or 1)

HighBitsOff=(0 or 1)

IndentAmount=(0 or 1)

InsertMode=(0 or 1)

RightMargin=(0 or 1)

TabFill=(0 or 1)

TabIncrement=(0 or 1)

UndoEnabled=(0 or 1)

UseRealTabs=(0 or 1)

Wordwrap=(0 or 1)

LeftOffset=(int)

TopOffset=(int)

RightOffset=(int)

BottomOffset=(int)

APIHelp=<help file pathname>	(Used for ME_HELPONWORD)

The fonts section contains the values which the editor will use for the default font. It has the following format :

[fonts]

height=<int height>             (defaults to 14)

face=<string>                   (defaults to Courier New)

UseOEMCharSet=<0 or 1>          (defaults to 0, DEFAULT_CHARSET)

UseFixedPitch=<0 or 1>          (defaults to 1, FIXED_PITCH)

These values are read in when the editor DLL initializes. The values are used as part of a call to the Windows API function CreateFont() in order to create the default edit control font.


Notifications When Reading a File

The editor DLL allows the application to monitor the action of reading a file into a buffer. The application may choose to take various actions while the file is being read. For example, the application can put up a 'progress indicator' window which keeps the end-user apprised to theamount of text read in. In another example, the application can check the amount of free space left in Windows while the file is being read and may choose to tell the editor to abort the reading if the amount of  free space gets too low.

The message to use in order to tell the Magma Editor DLL to perform application notifications is ME_SETREADNOTIFICATION. The wParam can be one of three ranges of values :

  wParam == 0	Do not perform notifications (the default)

  wParam > 0	Notify the app when every 'wParam' number of lines has been read. For example, if 	wParam is 100, then the application would be notified when every 100 lines are read.

  wParam < 0	Notify the app when every 'wParam' percent of the file has been read. For example, if 	wParam is -10, then the application is notified when an additional 10 percent of the file 	has been read in.

  Examples :

  SendMessage(hEdit, ME_SETREADNOTIFICATION, 100, 0L);  // every 100 lines

  SendMessage(hEdit, ME_SETREADNOTIFICATION, -10, 0L);  // every 10%

  SendMessage(hEdit, ME_SETREADNOTIFICATION, 0, 0L);    // no notification

If read notification is enabled, then the parent of the editor window will be notified at certain times with the ME_READNOTIFY message. The wParam of the ME_READNOTIFY can have three different values. The following values are passed in wParam

    READNOTIFY_START	Sent when the reading is just about to start

    READNOTIFY_READING	Sent when a certain increment of lines has been read

    READNOTIFY_END	Sent when the reading has been completed

The lParam is a far pointer to a READNOTIFYINFO structure. This structure is defined as follows :

typedef struct tagReadNotifyInfo

{

  int        nPercent;      /* percent of file read, 0-100 */

  int        nPrevPercent;  /* the prev value of nPercent  */

  DWORD      nBytesRead;    /* number of bytes read so far */

  DWORD      nTotalBytes;   /* total # of bytes to be read */

  LINENUMBER nLinesRead;    /* number of lines read so far */

} READNOTIFYINFO, FAR *LPREADNOTIFYINFO;

In the source code to the MEWIN demo program, a simple notification dialog is implemented in the file UIREAD.C. This simple dialog contains a textual display of the information passed in the READNOTIFYINFO structure, and is updated whenever the wParam is READNOTIFY_READING. The dialog box is destroyed when the app gets the ME_READNOTIFY message with wParam set to READNOTIFY_END.

Your application must return TRUE from the ME_READNOTIFY message. If it returns FALSE, then the editor will abort the reading at the current point. The editor buffer will contain all of the text which has been read up to the point of aborting. If you want to abandon the reading of the file at the beginning, then your app must return FALSE when it gets the ME_READNOTIFY message with wParam set to READNOTIFY_START.


Owner Drawn Lines

To test out owner-drawn controls, use the MEWIN demo which comes with the editor. If you start MEWIN with the -o argument, then it will make the edit buffer an owner-drawn buffer.  For example, the command

win mewin -o foo.c

would invoke the MEWIN editor with the ES_OWNERDRAW | ES_HASSTRING style.

When you give the -o argument to MEWIN, it creates edit buffers with the style

ES_OWNERDRAW | ES_HASSTRINGS

In this sample, MEWIN performs some syntax coloring. It searches for several reserved words in the C/C++ language and draws these words in a different color and with a bold-faced font.

When an edit control is owner-drawn, several messages are sent to the parent of the edit control.

The ME_MEASUREITEM message is sent to the parent window in order to allow your application to determine the height of a newly inserted line. See your favorite Windows API reference material on the ME_MEASUREITEM message and the corresponding MEMEASUREITEMSTRUCT data structure. The only difference is that the constant ODT_EDIT is put into the CtlType field of the MEMEASUREITEMSTRUCT.

If you process the ME_MEASUREITEM message, then you must do two things. First, you must put a valid value into the itemHeight field of the MEMEASUREITEMSTRUCT structure which is passed. Second, you must return the value TRUE from the parent's window procedure. If you return FALSE, then the edit control assigned the default height to the line (the default height is the height of the edit buffer's font).

When a line is deleted from the edit control, a ME_DELETEITEM message is sent to the parent window. See the Windows API documentation on the ME_DELETEITEM message and the corresponding MEDELETEITEMSTRUCT data structure. The only difference is that the constant ODT_EDIT is put into the CtlType field of the MEDELETEITEMSTRUCT.

The most important message is the ME_DRAWITEM message. Again, please see the Windows API documentation on this message. There is one important point here which you must keep in mind. Instead of sending a DRAWITEMSTRUCT structure, the Magma Edit DLL sends a MEDRAWITEMSTRUCT structure. This new structure contains some addition fields in it which the DRAWITEMSTRUCT does not have. In particular, it contains the lpText field, which points to the actual string which should be drawn. (Note: the entire text of the line is passed in lpText. You should also check the idxLeft field to see what position in the string your app should start the drawing.) Another important field is the lineNumber field, which contains the 0-based number of the line which you are asked to render. The definition of the MEDRAWITEMSTRUCT structure is contained in the main include file,  MAGMAED.H.

If your application draws the line, it must return TRUE in response to the ME_DRAWITEM message. Otherwise, if you return FALSE, then the edit control draws the line on its own.

To get a feel for how to proces the ME_DRAWITEM message, please see the file UIOWNDRW.C which comes with the MEWIN sample source code.

There are several other messages which are associated with the Magma Edit control, and these messages let you query and set the various components of a line's owner-draw information. These messages are :

ME_GETITEMDATA

ME_SETITEMDATA

ME_GETITEMHEIGHT

ME_SETITEMHEIGHT

It is also possible to insert images into your document using the owner-drawn styles. Magma Systems has

put embedded bitmap processing in the MEWIN editor code.  Start MEWIN with the -o option.

mewin -o foo

If foo has a line of text which starts in column 1 and has the following format :

<bitmap bitmapfilename>

where bitmapfilename is the pathname of a bitmap file, then the MEWIN ownerdraw code will render the bitmap in the edit control. (Make sure you have the left and right angle brackets too!)

For example, a line starting like this :

<bitmap mewin.bmp>

will read in the bitmap and draw it in the edit buffer at the proper line position.


Message Reference

Below is a list of messages which you can send to an editor window in order to perform editing operations, cursor movement, or configuration of the editor. The general form of sending a message is

result = SendMessage(hWndEdit, ME_xxx, wParam, lParam);

Most of the editor commands return TRUE if the command was performed successfully, and FALSE if the command failed.


Cursor Movement Messages

ME_MOVEUP

Move to the previous line

ME_MOVEDOWN

Move to the next line

ME_MOVELEFT

Move left one character

ME_MOVERIGHT

Move right one character

ME_MOVEBOL

Move to the beginning of the current line

ME_MOVEEOL

Move to the end of the current line

ME_MOVENEXTWORD

Move to the next word

ME_MOVEPREVWORD

Move to the previous word

ME_MOVENEXTPARA

Move to the next paragraph

ME_MOVEPREVPARA

Move to the previous paragraph

ME_MOVETOPOFWINDOW

Move to the upper-left corner of the editing window

ME_MOVEBOTOFWINDOW

Move to the lower-right corner of the editing window

ME_MOVENEXTPAGE

Move to the next page of text

ME_MOVEPREVPAGE

Move to the previous page of text

ME_MOVETOPOFBUFFER

Move to the top of the editing buffer

ME_MOVEBOTOFBUFFER

Move to the last character in the editing buffer

For all of the above commands, wParam and lParam are not used. The value TRUE is returned if the command was successful, and FALSE is returned if the command failed.

ME_GOTOLINE

Moves to a specific line of the editing buffer.

  wParam

    GOTOLINE_ABS  - lParam is the absolute line number

    GOTOLINE_NEXT - lParam is the # of lines from the current line

    GOTOLINE_PREV - lParam is the # of lines back from the current line

    GOTOLINE_LAST - go to the last line of the file. lParam is ignored.

  lParam is the line number

ME_MATCHBRACE

If the character at the current position is one of the following :

  {, }, (, ), [, ], "

attempts to find the matching brace or quote. If the match is found, the current position will be moved to the matched character.

Returns

TRUE if successful, FALSE if not.

ME_SETCOLUMN

Sets the current column withint he buffer.

Parameters

  wParam is the 0-based column to move the cursor to.

  lParam is not used.

Returns

  TRUE


Bookmark Messages

ME_MOVETOBOOKMARK

Moves the cursor to a specific bookmarked location.

Parameters

  wParam is the letter of the bookmark

  lParam is not used

Returns

  TRUE if the bookmark was moived to, FALSE if not.

ME_QUERYBOOKMARK

Queries the editor about the bookmarks which have been created. It returns an array of structures which contain the line number, column number, and letter of each bookmark.

Parameters

  wParam is the letter of the bookmark ('a' through 'z' or 'A' through 'Z').  If wParam is 0, then all booomarks will be retrieved.

  lParam is an array of BOOKMARKINFO structures. The BOOKMARKINFO structure is defined as

typedef struct tagBookmarkInfo

{

  DWORD lineNum;

  DWORD colNum;

  int   chBookmark;   /* 'A' through 'Z' */

} BOOKMARKINFO, FAR *LPBOOKMARKINFO;

Returns

  The number of bookmarks placed into the array.

ME_REMOVEBOOKMARK

Removes one or more bookmarks from the editing buffer.

Parameters

  wParam is the letter of the bookmark. It can be 'a' through 'z'. If wParam is the special value BOOKMARK_REMOVEALL, then all of the bookmarks associated with the editing buffer will be removed.

  lParam is not used

Returns

  TRUE if the bookmark was removed, FALSE if not.

ME_SETBOOKMARK

Sets a bookmark at the current cursor position.

Parameters

  wParam is the letter of the bookmark to set

  lParam is not used

Returns

  TRUE if the bookmark was set, FALSE if not.


Character Insertion & Deletion Messages

ME_BACKSPACE

Backspaces over the previous character and erases it

Parameters

  wParam is not used

  lParam is not used

ME_DELCHAR

Delete the character at the current position. If the character is a newline, the the next line will be joined to the current line.

Parameters

  wParam is not used

  lParam is not used

ME_DELEOL

Deletes all characters from the current line starting at the current position and going until the end of the line

Parameters

  wParam is not used

  lParam is not used

ME_DELWORD

Deletes the current word.

Parameters

  wParam is not used

  lParam is not used

ME_INSERTCHAR

Inserts a character at the current position. This function obeys the state of the editor's insert/overstrike mode.

Parameters

  wParam is the ASCII character to insert at the current position

  lParam is not used

ME_INSERTSTRING

Inserts a string into the editor at the current position.

Parameters

  wParam is ME_OVERSTRIKE_MODE if you want to overstrike the existing text at the current position in the buffer. Any other value for wParam will insert the text at the current position in the buffer.

  lParam is a far pointer to the text to insert. The text may have embedded tab characters (\t) or newlines (\n).

Returns

  TRUE if the text was inserted, FALSE if not.

Example

  SendMessage(hWndEdit, ME_INSERTSTRING, ME_INSERT_MODE,

              (LONG) (LPSTR) "This is line 1\nAnd this is line 2\n");

ME_TOGGLEINSERT

Toggles or sets the state of the insert/overstrike mode

Parameters

  wParam can be one of the following values :

INSERTMODE_TOGGLE	toggle the state

INSERTMODE_ON	sets insert mode

INSERTMODE_OFF	sets overstrike mode

  lParam is not used

ME_TOGGLEWORDWRAP

Toggles the current state of the wordwrap flag.

Parameters

  wParam can be one of the following values :

WORDWRAP_OFF	turns wordwrap off

WORDWRAP_ON	turns wordwrap on

WORDWRAP_TOGGLE	toggles wordwrap mode

  lParam is not used.

Returns

  Nothing.


File Input/Output Messages

ME_OPENFILE

Inserts the contents of a file at the current cursor position.

Parameters

  wParam is 0 if lParam points to a valid filename. You can pass the handle of an open file in wParam. If  you do this, then lParam must be 0.

  lParam is a far pointer to the name of the file to read. If lParam is 0, then wParam is assumed to contain the handle of an open file.

Returns

  TRUE if successful, FALSE if not.

ME_READNOTIFY

This message is sent by the editor DLL to the parent window of the edit control. It is sent at certain intervals in the file-reading process if the editor's read notification setting is on. Please see the ME_SETREADNOTIFICATION message for information on how to enable and disable read notification.

Parameters

  wParam can be one of the following values :

    READNOTIFY_START	Sent when the reading is just about to start

    READNOTIFY_READING	Sent when a certain increment of lines has been read

    READNOTIFY_END	Sent when the reading has been completed

  lParam is a far pointer to a READNOTIFYINFO structure.

Returns

  The application must return TRUE in order for the file reading to continue. If the application returns FALSE, then the editor DLL will abort the file reading at the current point.

ME_SETREADNOTIFICATION

This message is used to tell the Magma Editor DLL to notify its parent window at certain intervals when a file is being read .

Parameters

  wParam can be one of three ranges of values :

  wParam == 0	Do not perform notifications (the default state of the editor DLL)

  wParam > 0	Notify the app when every 'wParam' number of lines has been read. For example, if 	wParam is 100, then the application would be notified when every 100 lines are read.

  wParam < 0	Notify the app when every 'wParam' percent of the file has been read. For example, if 	wParam is -10, then the application is notified when an additional 10 percent of the file 	has been read in.

  lParam is not used.

Returns

  Nothing is returned.

ME_WRITEFILE

Writes the contents of the editor buffer to a file.

Parameters

  wParam is usually 0. If lParam is NULL, wParam may contain a file handle.

  lParam is a far pointer to the name of the file to write to. If  lParam is NULL and wParam is 0, then the filename already associated with  the editor window is used. If lParam is NULL and wParam is not zero, then wParam is interpeted as a file handle to write to.

Returns

  TRUE if successful, an error code if not. The error code can be one of the following values :

EN_ERRCREATING	could not create the file

EN_ERRWRITING	could not write out the entire editor buffer to the file.


Search and Replace Messages

Regular Expressions

The editor allows you to search forwards or backwards through a file for a certain "pattern" of text. In addition to searching for a series of characters, you can search for text which has a certain "property". For instance, you can ask the editor to locate all words which begin with the letter Q, or for all occurences of three digits in a row. The search command uses a very powerful mechanism called "regular expressions" to accomplish this.

The use of regular expressions has become very popular since the use of the UNIX operating system has become widespread. Although most operating systems (such as DOS) let you specify wildcards in the command line, UNIX carries the class of expressions further. For a good discussion of regular expressions, please see the book "Software Tools" by Kernighan and Ritchie, published by Addison Wesley. (UNIX is a trademark of AT&T.)

NOTE : The process of searching is done much faster if the editor detects that the pattern you specify does not contain any regular expression metacharacters. The editor uses an assembly language procedure which makes use of the fast 8088 string comparison instructions.

Metacharacters

When you invoke the search command, the editor will ask you for the text to search for. Certain characters have a special meaning in the search  pattern that you type. These characters are referred to as "metacharacters". Metacharacters should not be an alien concept to you. You have used metacharacters in DOS when you use the command "DIR R*.DOC"; the asterisk is a metacharacter which means "match 0 or more characters".

Here is a list of metacharacters which you can use when you type a pattern to search for :

<c>     Matches the character <c>.   For instance, abc will match an a followed by a b followed by a c.

?       Matches any single character .   For instance, a?c will match an a followed by any character   followed by a c.

*       Matches zero or more occurences of the previous character or  metacharacter.   For instance, ab* will find an a followed by zero or more bs.

+       Matches one or more occurences of the previous character or  metacharacter For instance, ab+ will find an a followed by one or more bs.

[c1-c2] A character class. Matches any character within the class. You can  list any characters within the class. If there is a dash  encountered in the class, then all characters starting from the character before the dash and ending with the character after the  dash will be included in the class.  For instance, [a-e] will match a,b,c,d, or e.        [a-ex-z] will match a through e or x through z.

[^c1-c2] Matches any character NOT IN the class.   For instance, [^a-z] will match any character which is not in lower case.

\       Takes the next character literally. This is called an  "escape" character. If the next character after the backslash is a c, a digit, or a parenthesis, the sequence is equivalent to one of the metacharacters discussed below.

^       Anchors the match at the beginning of the line.   For instance, ^abc finds a line which begins with "abc".

$       The match succeeds if at the end of the line.  For instance, abc$ finds a line which ends with "abc".

a|b     Matches pattern a or pattern b.

\c      If the match was successful, places the cursor at that position.

\(a\)   Tags pattern <a>. This tag can be referred to in subsequent  parts of the search pattern or in the substitution pattern.

\n      Refers to the tagged pattern <n>. N is a number from 1 to 9.

{ }	Parenthesizes an expression

The following shortcut patterns have been predefined and are available for you to use:

Meaning	Equivalent pattern

:a	alphanumeric character	[a-zA-Z0-9]

:b	whitespace character	 	[ \t]+

:c	alphabetic character 	[a-zA-Z]

:d	numeric character	[0-9]

:h	hex number	[0-9a-fA-F]+

:i	integer	[0-9]+

:l	valid C identifier	[a-zA-Z_][a-zA-Z_0-9]+

:w	word	[a-zA-Z]+

IMPORTANT - To search for a colon, you must prefix it with a backslash (ie - \:).

EXAMPLES OF SEARCH PATTERNS

abc	Matches abc.

^$	Matches a line with no characters. (the beginning of the line followed by the end of the 	line)

^abc	Matches a line which starts with abc.

^abc$	Matches a line which contains only abc.

[A-Z][0-9]	Matches a capital letter followed by a digit.

[^A-Za-z0-9]	Matches a character which is not alphanumeric.

be?t	Matches be, followed by any character, followed by a t.  (ie - bert, belt, bent).

ab*c	Matches an a, followed by zero or more bs, followed by  a c.

ab*\cc	Same as above, but places the cursor over the c after the match is completed. The "\c" 	places the cursor at the  position after "ab*" is matched.

ab\*c	Matches ab*c. Note that "\*" tells the pattern  matcher to take the asterisk literally.

{abc}+ 	Searches for one or more occurences of "abc".

[A-Z][A-Z]*[.?,! ]  Matches a capitalized word.

if|else	Matches the word if or the word else.

if|else|for	Matches if or else or for.

\(abc\)[0-9]\1	Matches abc, any digit, then abc. Note that "\1" refers to tagged pattern 1, which is 	"abc".

\([A-Z]+\)?*\1	Matches a line which contains two or more occurences of the same upper-case word. 	Note that "\1" refers to whatever  [A-Z]+ matched.

In order to search for a character which also doubles as a metacharacter, you must prefix that character with a backslash. For instance, if you wanted to search for a question mark, the search pattern would be "\?". To search for a backslash, the pattern is "\\".

Metacharacters in the Substitution Text

In the replacement pattern, you may use the metacharacter &. Whenever an & is encountered in the replacement pattern, the entire matched pattern will be substituted at that point.

For example, lets say that you specified abc as the pattern to search for. A replacement pattern of &xxx would change abc to abcxxx. Likewise, a replacement pattern of 12 && 34' would change abc to 12 abcabc 34'. To use a & literally in the replacement pattern, preceed the & by a backslash (\).

You may also include a tagged pattern in the replacement pattern. For example, lets say that the pattern that you searched for was :

          \(dog\) = \(cat\)

If you want to replace every occurence of "dog = cat" with "cat = dog", then the replacement pattern that you specify is :

          \2 = \1

This says that you want the new replacement pattern to be the first matched pattern ("dog") followed by " = ", followed by the second matched pattern ("cat").

To show a more powerful example, you can have the search pattern :

          \([a-z]+\)->prev = \([a-z]+\);

and the substitution pattern :

          \2->next = \1;

The pattern will match a sequence of lower case letters, followed by "->next = ", followed by another sequence of lower case letters, followed by a semi-colon. The first sequence of lower case letters that is matched is tagged as "\1", and the second sequence of lower case letters is tagged as "\2". This would change the line

          currentline->prev = newline;

to

          newline->next = currentline;

ME_FSEARCH

Search forward (from the current position) for a pattern.

ME_BSEARCH

Search backwards (from the current position) for a pattern.

ME_FREPLACE

Search forward (from the current position) for a pattern and substitute with a pattern.

ME_BREPLACE

Search backward (from the current position) for a pattern and substitute with a pattern.

Parameters

  wParam is not used

  lParam is the following :

For the search and substitute commands, lParam is a far pointer to a SEARCHARG structure. This is what the SEARCHARG structure looks like :

#define MAXPATTERNLEN  128

typedef struct tagSearchArg

{

  /*

    Flags for search & replace operation

  */

  UINT fFlags;

#define SEARCH_CASE_INSENSITIVE     0x0001  /* case insensitive search */

#define SEARCH_NO_REGEXP            0x0002  /* don't treat pattern as regex */

#define SEARCH_SELECTMATCH          0x0004  /* highlight the matched text */

#define SEARCH_WHOLE_WORD_ONLY      0x0008  /* match a whole word only */

#define SEARCH_PROMPT_ON_REPLACE    0x0100  /* prompt before replacing */

#define SEARCH_BACKWARD             0x1000  /* search backwards */

#define SEARCH_USE_VARWIDTH_PATTERN 0x2000

  /*

    This is the search pattern. The array is MAXPATTERNLEN chars long,

    unless SEARCH_USE_VARWIDTH_PATTERN is specified. In that case,

    the replacement pattern follows the NULL character in the search

    pattern.

  */

  char szPattern[MAXPATTERNLEN];

  /*

    This is the replacement pattern

  */

  char szReplacement[MAXPATTERNLEN];

} SEARCHARG, FAR *LPSEARCHARG;

The SEARCH_PROMPT_ON_REPLACE flag and szReplace[] string are only valid in the Substitute command

If lParam is NULL, then the editor will automatically bring up a dialog box for the search and substitute commands. This will allow the user to interactively enter the search and replace strings and the various

options.

Returns

  TRUE if the pattern was found, FALSE if not.

Example

SEARCHARG sa;

sa.fFlags = SEARCH_CASE_INSENSITIVE | SEARCH_PROMPT_ON_REPLACE;

lstrcpy(sa.szPattern, "Microsoft");

lstrcpy(sa.szReplacement, "Borland");

SendMessage(hEdit, ME_FREPLACE, 0, (LPARAM) (LPSEARCHARG) &sa);

ME_SEARCHAGAIN

Repeats the previous search operation.

Parameters

  wParam and lParam are not used

Returns

  TRUE if the pattern was found, FALSE if not.

ME_REPLACEAGAIN

Repeats the previous replace operation.

Parameters

  wParam and lParam are not used

Returns

  TRUE if the pattern was found, FALSE if not.

ME_QUERYSEARCHSTRING

Retrieves the last string used for searching.

Parameters

  wParam is not used

  lParam is the far pointer to a buffer which the search string will be copied to. lParam can be NULL.

Returns

  The length of the search string, or 0 or there was no previous search string.


Selecting, Cutting, Copying and Pasting Text

ME_APPENDLINE

Appends a blank line after the current line

Parameters

  wParam and lParam are not used

ME_CASELOWER

Changes the case of the selected text to all lower case

Parameters

  wParam and lParam are not used

ME_CASEUPPER

Changes the case of the selected text to all upper case

Parameters

  wParam and lParam are not used

ME_COPY

Copies the current selection, any marked lines, or the current line.  The copied text is placed into the clipboard.  If there is a currently marked selection, then the selected text is copied.  If there is no selected text, then the current line is copied.  The clipboard is cleared before the copied text is placed into it.

Parameters

  wParam and lParam are not used

ME_CUT

Deletes the current selection, any marked lines, or the current line.  The deleted text is placed into the clipboard.  If there is a currently marked selection, then the selected text is deleted.  If there is no selected text, then the current line is deleted.  The clipboard is cleared before the deleted text is placed into it.

Parameters

  wParam and lParam are not used

ME_CUTAPPEND

Deletes the current selection, any marked lines, or the current line.  The deleted text is placed into the clipboard.  If there is a currently marked selection, then the selected text is deleted.  If there is no selected text, then the current line is deleted.  The selected text is appended to the clipboard.

Parameters

  wParam and lParam are not used

ME_DELLINE

Deletes the current line or any marked lines. The deleted lines are not placed into the clipboard.

Parameters

  wParam and lParam are not used

ME_DUPLINE

Duplicates the current line and inserts it after the current line.

Parameters

  wParam and lParam are not used

ME_INSERTLINE

Inserts a blank line before the current line

Parameters

  wParam and lParam are not used

ME_MARKLINE

Toggles the marked state of the current line.

Parameters

  wParam and lParam are not used

ME_MARKLINERANGE

Marks all lines from the current line up to the previously marked line.  The previously marked line must physically above the curent line.

Parameters

  wParam and lParam are not used

ME_PASTE

Inserts the contents of the pick buffer at the current position

Parameters

  wParam and lParam are not used

Notes

The WM_PASTE message pastes from the clipboard. On the other hand, the ME_PASTE message pastes from the internal Magma Editor pick buffer. The ME_PASTE message understands column pastes, whereas the WM_PASTE message does not.

ME_RECTMARK

Starts or ends a 'column' selection. If this message is sent when there are no selected areas of text, then the editor will 'mark' the current cursor position. You can then move the cursor anywhere in the buffer. When the second ME_STREAMMARK message is received by the editor, it will select the columns of text between the starting and ending selection points.

Parameters

  wParam and lParam are not used

ME_RESETMARK

Clears all selections from the current buffer. If any text is selected,  then it will become deselected.

Parameters

  wParam and lParam are not used

ME_STREAMMARK

Starts or ends a 'stream' selection. If this message is sent when there are no selected areas of text, then the editor will 'mark' the current cursor position. You can then move the cursor anywhere in the buffer. When the second ME_STREAMMARK message is received by the editor, it will select all text between the starting and ending selection points.

Parameters

  wParam and lParam are not used

ME_TAB

ME_BACKTAB

Indents the selected lines rightwards or leftwards. The ME_TAB command pushes the text rightwards, and the ME_BACKTAB command pushes the text leftwards.

Parameters

  wParam and lParam are not used


Formatting Messages

ME_CENTER

Centers a line of text. The value of the RightMargin editor option  is used for the right border.

Parameters

  wParam and lParam are not used.

Returns

  Nothing.

ME_REFORMAT

Reformats a paragraph so that it fits between the left and right margins.

Parameters

  wParam and lParam are not used.

Returns

  Nothing.

ME_REFORMATALL

Reformats a the entire document, one paragraph at a time, so that it fits between the left and right margins.

Parameters

  wParam and lParam are not used.

Returns

  Nothing.

ME_TRIMTEXT

Manipulates the spaces within a string in a variety of ways.

Parameters

  wParam can be a combination of one or more of the following :

TRIM_LEADING_BLANKS	Removes leading spaces from the string.

TRIM_TRAILING_BLANKS	Removes trailing spaces from the string.

TRIM_COMPRESS_BLANKS	Compresses multiple spaces into a single space.

  lParam can be a far pointer to a string. If lParam is NULL, then the text of the current line in the editing buffer is used.

Returns

  Nothing.


Undo Messages

ME_REDO

Undoes the previous undo.

Parameters

  wParam and lParam are not used

ME_UNDO

Undoes the previous editing command.

Parameters

  wParam and lParam are not used


Configuration Messages

ME_OPTIONDLG

Invokes the "Options" dialog box. This provides an interactive way for the user to configure the editor.

Parameters

  wParam and lParam are not used

ME_SETOPTION

Sets a specific editor option.

Parameters

  wParam is the new value

  lParam is a far pointer to the name of the option

Name	Default	Meaning

AutoIndent	1	Are new lines auto-indented

AutoReformat	0	Reformat lines automatically after text is inserted

EntabLine	0	Lines are entabbed when written to a file

GoFreeSpace	1	Can the cursor move into space beyond the end-of-line

HighBitsOff 	0	Editor masks out the high bit of characters

IndentAmount	2	The amount of space each indent/undent command shifts

InsertMode	1	The initial insert/overstrike mode  (1 = insert)

RightMargin	80	The margin where wordwrapping will take effect

TabFill	32	The fill character used for tabs

TabIncrement	8	The width of a tab stop

UndoEnabled	1	Undo enabled

UseRealTabs	0	Use real tabs or insert spaces instead of tabs

Wordwrap	0	Wordwrap enabled

LeftOffset	0	Space betwen left border and left side of edit drawing area

TopOffset	0	Space betwen top border and top of edit drawing area

RightOffset	0	Space betwen right border and right side of edit drawing area

BottomOffset	0	Space betwen bottom border and bottom of edit drawing area

ME_QUERYOPTION

Queries the current value of a specific editor option.

Parameters

  wParam is not used.

  lParam is a far pointer to the name of the option

Returns

  The current value of the editor option.

ME_SETTEXTCOLOR

Sets the color of the text.

Parameters

  wParam not used

  lParam is the RGB color

ME_SETBKCOLOR

Sets the color of the editor window background.

Parameters

  wParam not used

  lParam is the RGB color

EM_SETBKGNDCOLOR  (Chicago compatible)

Sets the color of the editor window background.

Parameters

  wParam is TRUE to use system color, FALSE for RGB value in lParam

  lParam is the RGB value

Returns

  The old background color


Owner Drawn Messages

ME_DELETEITEM

This message is sent to the window procedure of the parent of the edit control. It is sent just before a line of text is deleted from the editing buffer. This message gives the application a chance to perform any clean-up associated with the deletion of the line.

Parameters

  wParam is the control identifier of the edit control.

  lParam is a far pointer to a MEDELETEITEMSTRUCT structure.

Returns

  The return value from the window procedure is not used by the editor DLL.

ME_DRAWITEM

This message is sent to the window procedure of the parent of the edit control. It is sent when a line of text needs to be drawn into the window associated with the editing buffer.

Parameters

  wParam is the control identifier of the edit control.

  lParam is a far pointer to a MEDRAWITEMSTRUCT structure.

Returns

  The window procedure must return TRUE if it did the drawing of the line. If the window procedure returns FALSE, then the editor DLL will draw the line itself.

ME_MEASUREITEM

This message is sent to the window procedure of the parent of the edit control. It is sent when a new line of text is inserted into the editing buffer. This message gives the application a chance to tell the editor DLL how high the line is.

Parameters

  wParam is the control  identifier of the edit control.

  lParam is a far pointer to an MEMEASUREITEMSTRUCT data structure.

Returns

  The window procedure should return a non-zero height. This will be the height of this particular line in the file. If the window procedure returns 0, then the height will default to the height of the editor font.

ME_GETITEMDATA

Queries the item-data value of a line in the edit buffer. Each line in an owner-drawn edit buffer can have a 4-byte value associated with it. This value is passed in the itemData field of the  MEMEASUREITEMSTRUCT, MEDELETEITEMSTRUCT, and MEDRAWITEMSTRUCT.

Parameters

  wParam is the 0-based line number. If lParam is not 0, then the value in lParam is used as the line number.

  lParam can be the 0-based line number.

Returns

  The application-defined 4-byte data value which is associated with a line.

ME_SETITEMDATA

Sets the item-data value of a line in the edit buffer. Each line in an owner-drawn edit buffer can have a 4-byte value associated with it. This value is passed in the itemData field of the  MEMEASUREITEMSTRUCT, MEDELETEITEMSTRUCT, and MEDRAWITEMSTRUCT.

Parameters

  wParam is the 0-based line number.

  lParam contains the 4-byte value which is associated with the line.

Returns

  TRUE if set, LB_ERR if not set.

ME_GETITEMHEIGHT

Queries the owner-drawn height of a line in the edit buffer.

Parameters

  wParam is the 0-based line number. If lParam is not 0, then the value in lParam is used as the line number.

  lParam can be the 0-based line number.

Returns

  The height of the line.

ME_SETITEMHEIGHT

Sets the owner-drawn height of a line in the edit buffer.

Parameters

  wParam is the 0-based line number.

  lParam contains the pixel height of the line.

Returns

  TRUE if set, LB_ERR if not set.


Status Messages

ME_GETCURRWORD

Retrieves the word under the cursor and puts it in an app-passed buffer.

Parameters

  wParam is the length of the buffer

  lParam is a far pointer to the buffer to copy the word into

Returns

  The length of the string if successful, 0 if not.

ME_QUERYNUMWORDS

Queries the number of words in the editor buffer.

Parameters

  wParam and lParam are not used.

Returns

A double-word value which contains the number of words in the editor buffer.

ME_QUERYSTATUS

This message retrieved certain information about the editing buffer. Information includes the current column, current line number, and the total number of lines in the buffer.

Parameters

  wParam is not used.

  lParam is a far pointer to an MAGMAED_STATUS structure.

Returns

  TRUE if the infomation was retrieved, FALSE if not.


Keyboard Macro Messages

ME_KEYMACDEFINE

Starts and stops the recording of a keyboard macro. To begin recording a keyboard macro, send the ME_KEYMACDEFINE message to the editor. To stop the recording, send this message again.

Parameters

  wParam and lParam are not used

ME_KEYMACPLAY

Plays the currently-defined keyboard macro

Parameters

  wParam and lParam are not used


Windows API Messages

The following messages are provided for compatibility with the standard Windows edit control.

WM_GETFONT

Retrieves the handle of the font which the edit control is using.

Parameters

  wParam and lParam are not used.

Returns

The handle of the currently selected font.

WM_GETTEXT

Retrieves the contents of the edit control and puts the text into the passed memory location.

Parameters

  wParam is the maximum size of the text to be copied.

Note:   A limitation is that wParam contains the max length of the buffer, which under 16-bit Windows, can be at most 64K. So, we will add a little extension here. If wParam is 0, then we will not check the length of the buffer.

  lParam is a far pointer to the memory location which will receive the text.

Returns

The number of bytes copied into the memory location, or 0 if not successful.

WM_GETTEXTLENGTH

Queries the length of the text in the edit control.

Parameters

  wParam and lParam are not used.

Returns

The number of characters in the edit control. This double-word value can be greater than 64K.

WM_SETFONT

Sets the font which the edit control should use.

Parameters

  wParam is the handle of the font which you want the edit control to use.

  lParam is not used.

Returns

The handle of the currently selected font.

WM_SETREDRAW

Sets the refresh state of the buffer.

Parameters

  wParam can be zero or non-zero. If it is zero, then buffer refreshes will be disabled. This means that mulitple editing operations can be performed without the buffer refreshing the window after each

operation. If wParam is non-zero, then refreshing will be enabled.

  lParam is not used.

Returns

  Nothing

WM_SETTEXT

Sets the contents of the edit control to the specified text.

Parameters

  wParam is not used.

  lParam is a far pointer to the text to set.

Returns

  TRUE if successful, FALSE if not.

EM_GETFIRSTVISIBLELINE

Queries the line number of the line which is at the top of the editor window.

Parameters

  wParam is not used.

  lParam is not used.

Returns

  The 0-based line number of the line at the top of the window.

EM_GETLINE

Retrieves the contents of a specified line.

Parameters

  wParam is the 0-based line number of the line to query.

  lParam is a far pointer to a memory location where the contents of the line will be copied to.

Returns

  The number of bytes copied.

EM_GETLINECOUNT

Queries the number of lines in the edit control.

Parameters

  wParam is not used.

  lParam is not used.

Returns

  The number of lines in the editor.

EM_GETSELTEXT  (Chicago compatible)

This message retrieves the text which is currently selected.

Parameters

  wParam is 0

  lParam is a far pointer to a buffer which the text will be placed into.

Returns

  TRUE if there was selected text, FALSE if not.

Notes

The editor does not check the length of the the buffer pointed to by lParam. It is up to the application to insure that the buffer is large enough to hold the selected text.

EM_LINEFROMCHAR

Given a 0-based index into the editor, returns the line number of the line which contains the character.

Parameters

  wParam contains the 0-based index of the character.

Note :  A limitation is that wParam contains the max length of the buffer, which under 16-bit Windows, can be at most 64K. So, we will add a little extension here. If lParam is not 0, then we will use the value in lParam as the index.

  lParam must be 0 if you are using wParam as the index. Otherwise, lParam will be used as the index.

Returns

  The 0-based line number.

EM_EXLINEFROMCHAR  (Chicago compatible)

See the EM_LINEFROMCHAR message.

Parameters

  wParam is 0

  lParam is the index

EM_LINEINDEX

Given the number of a line, returns the 0-based index of the first character on that line.

Parameters

  wParam is the 0-based line number. If lParam is not 0, then lParam is used as the line number.

  lParam should be 0 if you are using wParam to hold the line number. Otherwise, lParam can hold the line number.

Returns

The 0-based index of the first character on the line. If wParam contains a line number which is greater than the number of lines in the edit control, then -1 is returned.

EM_LINELENGTH

Queries the number of characters in a certain line.

Parameters

  wParam is the 0-based index of a character in the buffer. This index will be used to detrmine the line to query. If lParam is not 0, then lParam holds the character index.

  lParam should be 0 if wParam holds the character index. Otherwise, the value in lParam will be used as the character index.

Returns

The number of characters in the line, or 0 if the line number does not exist.

EM_GETMODIFY

Queries the modification state of the edit control.

Parameters

  wParam is not used.

  lParam is not used.

Returns

Non-zero if the edit control has been modified, 0 if not.

EM_SETMODIFY

Sets the modification state of the edit control.

Parameters

  wParam is the new modification state. It should be non-zero if the edit control should be considered to have been modified, and zero if you want to clear the modification state.

  lParam is not used.

Returns

The new modification state.

EM_GETSEL

Queries the current selection points.

Parameters

  wParam and lParam are not used.

Returns

If an area of text has been selected, then the low word of the return value is the starting index of the selection and the high word of the return value is the index of the last selected character plus 1. If an area is not selected, then both the low word and high word of the return value contain the index where the cursor is currently positioned.

EM_REPLACESEL

Replaces the selected text with another string.

Parameters

  wParam is not used.

  lParam is a far pointer to a string to use to replace the selected text with.

EM_SETSEL

Sets the current selection points. Each selection point must be an index less than 64K. See the EM_EXSETSEL message if you need to select an area in a buffer which contains more than 64K of text.

Parameters

  wParam is 0.

  The low word of lParam is the index of the starting point of the selected area. The high word of lParam is the index of the first character after the starting selection index which is not selected.

EM_EXGETSEL  (Chicago compatible)

Queries the current selection points. Each selection point can be a number greater than 64K.

Parameters

  wParam is 0

  lParam is a far pointer to a CHARRANGE structure

EM_EXSETSEL  (Chicago compatible)

Sets the current selection points. Each selection point can be a number greater than 64K.

Parameters

  wParam is 0

  lParam is a far pointer to a CHARRANGE structure

EM_SETREADONLY

Modifies the 'read-only' state of the edit control.

Parameters

  wParam is non-zero if the read-only state should be set, and zero if it should be cleared.

  lParam is not used.

Returns

TRUE if successful, FALSE if not.

EM_SETTABSTOPS

Sets the tab stops of the edit control.

Parameters

  wParam specifies the number of tab stops contained in the lpTabs array pointed to by lParam. If wParam is 1, then the value in lpTabs[0] contains tab increment multiplied by 4; the tabs will be set every lpTabs[0]/4 number of columns. If wParam is 0, then the default tab settings are used. If wParam is greater than 1, then lpTabs is an array of tab stops.

  lParam is a far pointer to an array of tab stops. Each tab stop represents a column number multiplied by 4. The value 4 is equivalent to the Windows dialog unit.

If the values in the tab array are positive, they are interpreted as column values. For example,

  static int aiTabs[] = { 30, 55, 68, 74 };

  SendMessage(hEdit, EM_SETTABSTOPS, 4, (LPARAM) (LPINT) aiTabs);

will set a tab stop at character columns 30, 55, 68 and 74. This is consistent with the way which most DOS text editors work.

If the values in the tab array are negative, then the values are considered to be pixel positions.

Returns

TRUE if the tabs were set, FALSE if not.


Help Messages

ME_HELPONWORD

Gets help on the word under the cursor. The Windows help file used is the one which is in the APIHELP entry in [options] section of the MAGMAED.INI file.

Parameters

  wParam is not used.

  lParam can contain a far pointer to the file name of the help file to use. If lParam is 0, then the help file used is the one found in the MAGMAED.INI file.

Returns

  TRUE if successful, FALSE if not.

Example

SendMessage(hEdit, ME_HELPONWORD, 0, (LPARAM) (LPSTR) "myapp.hlp");


Notification Codes

MEN_UPDATE

This notification code is sent when the state of the editor has changed.  A WM_COMMAND message will be sent to the window which is the parent of  the editor window. The wParam will be the control ID of the editor window, the LOWORD of the lParam will be the window handle of the editor window, and the HIWORD of the lParam will be the MEN_UPDATE code.

A typical use for this message is to update the "editor decorations"  in your application when something in the editor has changed. For example, if your application maintains a status line for the editor, then you can use the following code in your application in order to update the status line:

    case WM_COMMAND:

      if (HIWORD(lParam) == MEN_UPDATE)

      {

        InvalidateRect(hWndStatus, (LPRECT) NULL, FALSE);

        break;

      }

EN_CHANGE

The contents of the edit control have been altered

EN_HSCROLL

The edit control's horizontal scrollbar has been clicked on

EN_KILLFOCUS

The edit control is losing the focus

EN_SETFOCUS

The edit control has gained the focus

EN_VSCROLL

The edit control's horizontal scrollbar has been clicked on